﻿using System.ComponentModel;
using BlueDot.Data.Core;
using BlueDot.Mobile.Core;
using CancelWorkFlowStep.Model;

namespace CancelWorkFlowStep.Controllers
{
    public class MainController : ControllerBase
    {
        #region Fields

        private const string USER_STATEBAG_KEY = "users";

        #endregion

        #region public

        /// <summary>
        /// Returns list of users loaded in the statebag
        /// </summary>
        /// <returns></returns>
        public EntityDataView<User> GetUsers()
        {
            var users = (EntityDataView<User>) StateBag[USER_STATEBAG_KEY].Value;

            if (users == null)
            {
                users = new EntityDataView<User>
                            {
                                EntityList = new BindingList<User>()
                            };
                StateBag[USER_STATEBAG_KEY].Value = users;
            }

            return users;
        }

        #endregion
    }
}